package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLessonChapter;

public interface YxyLessonsSchoolLessonChapterRepository extends JpaRepository<YxyLessonsSchoolLessonChapter, String> {

    List<YxyLessonsSchoolLessonChapter> findByLessonId(String lessonId);

    List<YxyLessonsSchoolLessonChapter> findByLessonIdOrderByOrderNum(String lessonId);

    YxyLessonsSchoolLessonChapter findByLessonIdAndTitle(String lessonId, String title);

    // 查询课程全部已添加章节
    @Query(value = " select t1 from YxyLessonsSchoolLessonChapter t1 where t1.lessonId = ?1 order by t1.orderNum asc")
    List<YxyLessonsSchoolLessonChapter> findLessonChapterByLessonId(String lessonId);

    Integer countByLessonId(String lessonId);

    Integer countByLessonIdAndIdIn(String lessonId, List<String> chapterIds);

    @Query(value = " select max(t1.orderNum)  from YxyLessonsSchoolLessonChapter t1 where t1.lessonId = ?1")
    Integer findMaxOrderNumLessonChapterByLessonId(String lessonId);

    @Query(value = " select t1  from YxyLessonsSchoolLessonChapter t1 where t1.orderNum = ?1")
    YxyLessonsSchoolLessonChapter findByOrderNum(Integer orderNum);

    YxyLessonsSchoolLessonChapter findById(String chapterId);

    List<YxyLessonsSchoolLessonChapter> findByLessonIdOrderByOrderNumAsc(String lessonId);
}
